﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Adonet
{
    class Program
    {
        static void Main(string[] args)
        {
            string connstr = "server=.;database=Users2;uid=sa;pwd=1218";
            SqlConnection conn = new SqlConnection(connstr);
            conn.Open();
            var SelectSQL = "select *from Factory";
            SqlCommand command = new SqlCommand(SelectSQL, conn);

            var reader = command.ExecuteReader();
            while (reader.Read())
            {
                Console.WriteLine("{0}\t{1}", reader["Factoryid"], reader["Factoryname"]);
            }
            conn.Close();





            string connstr1 = "server=.;database=Users2;uid=sa;pwd=1218";
            SqlConnection conn1 = new SqlConnection(connstr1);
            conn.Open();
            SqlCommand command1 = new SqlCommand(SelectSQL, conn);

            command.CommandText = "insert into Factory values (1,'出版社')";
            command.ExecuteNonQuery();

            conn.Close();




            string connstr2 = "server=.;database=Users2;uid=sa;pwd=1218";
            SqlConnection conn2 = new SqlConnection(connstr2);
            conn.Open();
            SqlCommand command2= new SqlCommand(SelectSQL, conn);

            command.CommandText = "Delete from FactoryName '出版社'";
            command.ExecuteNonQuery();
            conn.Close();
        }            
    }
}
